package de.pipeGame.itemStack;

import java.util.HashMap;

import de.pipeGame.GamePreset;
import de.pipeGame.Level;
import de.pipeGame.R;
import de.pipeGame.R.id;
import de.pipeGame.R.layout;

import EventSourcing.DragComponent;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * The ItemStackHolder handles all stacks in a HashMap
 * @author Anthea
 *
 */
public class ItemStackHolder{

	private HashMap<Integer, ItemStack> itemStacks;
	Level level;
	
	public ItemStackHolder(Context context, ViewGroup item_stack,Level level){
		itemStacks = new HashMap<Integer,ItemStack>();
		this.level = level;
		
		LayoutInflater  mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

		for (int it_type = 0; it_type < level.getItemStacks().length; it_type++ ){
			int type_amount = level.getItemStacks()[it_type];
			
			if (type_amount!=0){
				ViewGroup itemGroup = (ViewGroup) mInflater.inflate(R.layout.pipe_item_button,item_stack , false);
				((TextView)itemGroup.findViewById(R.id.text)).setText(type_amount+" x");
				((ImageView)itemGroup.findViewById(R.id.image)).setImageResource(GamePreset.getDrawableForPipeType(it_type));
				item_stack.addView(itemGroup);
				itemStacks.put(it_type,new ItemStack(itemGroup,it_type,type_amount));
			}
		}
	}
//
//	/**
//	 * removes one item from a specific stack
//	 * @param ob the item id, you can find it in the GamePreset class
//	 */
//	public void decreaseItem(int ob) {
//		 itemStacks.get(ob).decreaseItems();
//		
//	}

	public ItemStack get(int ob) {
		return itemStacks.get(ob);
	}
}
